package microservice.registory;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: rocsun
 * @description: 专用健康检查节点
 * @author: yx.guo
 * @create: 2025-08-07 22:49
 **/
@RestController
public class HealthController {
    @GetMapping("/health")
    public ResponseEntity<HealthStatus> checkHealth() {
        // 检查数据库连接、缓存、消息队列等依赖
        boolean dbHealthy = checkDatabase();
        boolean cacheHealthy = checkCache();

        if(dbHealthy && cacheHealthy) {
            return ResponseEntity.ok(new HealthStatus("UP"));
        }
        return ResponseEntity.status(503).body(new HealthStatus("DOWN"));
    }

    private boolean checkCache() {
        return true;
    }

    private boolean checkDatabase() {
        return true;
    }

    public static class HealthStatus{
        String status;

        public HealthStatus(String status) {
            this.status = status;
        }
    }


}
